package com.guang.base.dto;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guang.base.BaseBean;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class PageDto extends BaseBean {

    //当前页
    private Integer currentPage = 1;

    //显示条数
    private Integer showCount = 10;

    //是否查询count
    private Boolean searchCount;

    //如果存在这个lastId，并且searchCount=false，则进行优化
    private Long lastId;

    public PageDto() {
    }

    public PageDto(Integer currentPage, Integer showCount) {
        this.currentPage = currentPage;
        this.showCount = showCount;
    }

    public <T> Page<T> toMpDefault() {
        if (null == showCount) {
            this.showCount = 10;
        }
        if (null == currentPage) {
            this.currentPage = 1;
        }
        return toMp();
    }

    public <T> Page<T> toMp() {
        Page<T> page = new Page<>(this.currentPage, this.showCount);
        if (ObjectUtil.isNotNull(this.searchCount)) {
            page.setSearchCount(this.searchCount);
        }
        if(this.getLastId() != null){
            page.setCountId(this.getLastId().toString());
        }
        return page;
    }
}
